USE [oktell]
GO
/****** Object:  StoredProcedure [dbo].[A_TaskManager_OperatorsAll_Get_Custom]    Script Date: 01/20/2014 10:40:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER  Procedure [dbo].[A_TaskManager_OperatorsAll_Get_Custom]
	@idtask		uniqueidentifier = '00000000-0000-0000-0000-000000000000',
	@idlist		uniqueidentifier = '00000000-0000-0000-0000-000000000000',
	@idabonent	int = 0,
	@idline		uniqueidentifier = '00000000-0000-0000-0000-000000000000',
	@dtnow 		datetime = null
as
begin
/* 
       .
       .
         
 ,    - , , , , ...
    ,  ,  ,   .
 ,          "CUSTOM"  , 
     .

   ,       -  
     . 
,     -     (     
     ).  ,     
 -     ,     
  -  .
*/ 
		
	
	if (@idtask = 'B8A22910-BFA4-480D-BFB1-151D0C06F93B')
	begin
		
		declare @Id uniqueidentifier
		
		select	@Id = operatorid
		from TableMain	
		where Id = @idabonent
		
		if (@Id is null)
			begin
				select	u.Id
				from	A_Users u
							inner join A_UserParams up on u.Id = up.Iduser
				where	IsOperator = 1
				order by NEWID()
			
			--select '6156BDD9-40CF-4AA2-9B90-AA4E9B7A3A23'	
			end
		else
			begin
				select @Id Id
			end
		
		return
	end
	
	-- 
	Select Id
	FROM A_Users u
	Inner join A_UserParams up on u.Id = up.Iduser
	Where IsOperator = 1
	

end
